<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://unpkg.com/react@18.1.0/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@18.1.0/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
    <title>Document</title>
  </head>
  <body>
    <script type="text/babel">
      // 非受控组件：是React提供的用于操作DOM的方法，在某些情况下，操作DOM可能会更加方便快捷。React不鼓励操作真实DOM，但特殊情况除外。
      class App extends React.Component {
        constructor() {
          super();
          this.state = {};
          // 1. 创建Ref对象
          this.divRef = React.createRef();
        }
        clickEvent() {
          let div = this.divRef.current;
          div.style.width = "100px";
          div.style.height = "100px";
          div.style.backgroundColor = "yellow";
        }
        render() {
          return (
            <div className="app">
              {/* 2. 将 divRef 设置在目标DOM的ref属性上 */}
              <div className="test" ref={this.divRef}>
                div
              </div>
              <button onClick={this.clickEvent.bind(this)}>操作DOM</button>
            </div>
          );
        }
      }
      ReactDOM.render(<App />, document.getElementById("app"));
    </script>
  </body>
</html>
